home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-02-15 | 6.3 KB | 208 lines | [TEXT/PJMM] |
- unit Layers;
-
- {This unit was adapted to THINK Pascal 4.0 by David B. Lamkins from}
- {a CSMP posting by Michael Hecht, which was in turn derived from an}
- {earlier posting by Hugues Marty, hugues@isoftfr.isoft.fr.}
- {}
- {From: Michael Hecht,Michael_Hecht@mac.sas.com,Internet}
- {}
- {>For a program I'm working on I'd like to be able to launch an}
- {>application and then "hide" it, in a manner similar to the way the OS}
- {>hides an app when the user chooses "Hide..." from the application menu.}
- {}
- {What you need is info on the undocumented "Layer Manager". Each}
- {application has a "layer" which is similar to a window. In fact, you can}
- {use the HideWindow and ShowWindow calls on a layer to do what you want.}
- {The layer's "visible" field tells you if the layer is showing or hidden.}
- {}
- {I discovered that there seems to be a layer whose elements are not}
- {windows, but the layers of all running processes. I called this a}
- {metaLayer, and discovered that a layer with the goAwayFlag set indicates}
- {a metaLayer. Each process' layer has this metaLayer as a parent, and this}
- {metaLayer has another metaLayer as its parent (I don't know why). This}
- {metaLayer seems to be topmost, as its parent is NIL. I called this}
- {topmost layer the deskLayer, since it seems to describe the entire desktop.}
- {}
- {I also found a neat routine that calls back an action proc for each}
- {window of each layer. I called this ForEachLayerWindowDo. I'm a bit hazy}
- {on the first three parameters--they seem to describe the bounds of the}
- {search. I think they're a starting layer, a starting window, and maybe a}
- {parent layer, but I'm not quite sure how they interact. It seems you're}
- {able to pass -1, 0, or an actual LayerPtr or WindowPtr for them.}
-
- interface
-
- uses
- Processes;
-
- type
- {This records some information on the process which owns}
- {the layer… Most of it is not clear (there are pointers}
- {to other LayerRecords, to a heap zone, etc. in the unknown parts.}
- LayerInfo = record
- unknown1: Longint;
- signature: OSType;
- creator: OSType;
- unknown2: packed array[1..24] of SignedByte;
- layerPSN: ProcessSerialNumber;
- unknown3: packed array[1..40] of SignedByte;
- moreLayerInfo: Handle; {size = 212, contents = ?}
- end;
- LayerInfoPtr = ^LayerInfo;
-
- LayerPtr = WindowPtr;
- LayerRecord = record
- port: GrafPort; {txSize = $DEAD}
- windowKind: Integer;
- visible: Boolean; {the layer’s visibility: HideWindow}
- hilited: Boolean;
- metaLayer: Boolean; {a layer of layers}
- spareFlag: Boolean;
- strucRgn: RgnHandle;
- contRgn: RgnHandle;
- updateRgn: RgnHandle;
- windowDefProc: Handle;
- parentLayer: LayerPtr; {layer of which this is a member}
- auxWinHead: AuxWinHandle; {this layer’s AuxWinHead}
- titleWidth: Integer;
- auxCtlHead: AuxCtlHandle; {this layer’s AuxCtlHead}
- nextLayer: LayerPtr; {next layer in the chain}
- windowList: WindowPtr; {this layer’s WindowList}
- layerInfo: LayerInfoPtr; {this layer’s add' l info : GetWRefCon}
- end;
- LayerPeek = ^LayerRecord;
-
- const
- kNextWindow = 0;
- kNextLayer = 700;
- kBreak = 701;
-
- type
- WindowActionCode = Integer;
- LayerActionProcPtr = ProcPtr;
- {$IFC False}
- {This is how the LayerActionProc is defined.}
- function LayerActionProc (theWindow: WindowPtr; theLayer: LayerPtr; refCon: Longint): WindowActionCode;
- {$ENDC}
-
- const
- kAllLayers = -1;
-
- {Call the action proc for each window in each layer}
- function ForEachLayerWindowDo (layer1, layer2, layer3: LayerPtr; layerAction: LayerActionProcPtr; refCon: Longint): WindowActionCode;
- inline
- $70F8, $A829;
-
- {Return the window's layer}
- function WindowLayer (theWindow: WindowPtr): LayerPtr;
- inline
- $70F9, $A829;
-
- {Return the frontmost visible window in the given layer}
- function LayerFrontVisibleWindow (theLayer: LayerPtr): WindowPtr;
- inline
- $70FD, $A829;
-
- {Return the frontmost visible window on the desktop}
- function DeskFrontVisibleWindow: WindowPtr;
- inline
- $70FE, $A829;
-
- {Return the desktop's layer (contains all other layers)}
- function DeskLayer: LayerPtr;
- inline
- $70FF, $A829;
-
- {Return TRUE if theLayer is really a LayerPtr; return FALSE if it's a WindowPtr}
- function IsLayer (theLayer: LayerPtr): Boolean;
- inline
- $7002, $A829;
-
- {Return the current process’ layer}
- function CurrentLayer: LayerPtr;
- inline
- $7003, $A829;
-
- {Return the first window of this layer}
- function LayerFrontWindow (theLayer: LayerPtr): WindowPtr;
- inline
- $7006, $A829;
-
- {All-layer version of FindWindow}
- function FindLayerWindow (where: Point; var foundWindow: WindowPtr): Integer;
- inline
- $7007, $A829;
-
- {Returns true if this later is visible}
- function LayerVisible (aLayer: LayerPtr): Boolean;
-
- {Return the layer following this one}
- function GetNextLayer (aLayer: LayerPtr): LayerPtr;
-
- {Get a pointer to the layer info record for this layer}
- function GetLayerInfo (aLayer: LayerPtr): LayerInfoPtr;
-
- {Hide this layer}
- procedure HideLayer (aLayer: LayerPtr);
-
- {Show this layer}
- procedure ShowLayer (aLayer: LayerPtr);
-
- {Show or hide this layer}
- procedure ShowHideLayer (aLayer: LayerPtr; showFlag: Boolean);
-
- {Return true if this layer is hidden}
- function HiddenLayer (aLayer: LayerPtr): Boolean;
-
- {Return the name of this layer}
- function GetLayerName (aLayer: LayerPtr): Str255;
-
-
- implementation
-
- function LayerVisible (aLayer: LayerPtr): Boolean;
- begin
- LayerVisible := LayerPeek(aLayer)^.visible
- end; {LayerVisible}
-
- function GetNextLayer (aLayer: LayerPtr): LayerPtr;
- begin
- GetNextLayer := LayerPeek(aLayer)^.nextLayer;
- end; {GetNextLayer}
-
- function GetLayerInfo (aLayer: LayerPtr): LayerInfoPtr;
- begin
- GetLayerInfo := LayerPeek(aLayer)^.layerInfo;
- end; {GetLayerInfo}
-
- procedure HideLayer (aLayer: LayerPtr);
- begin
- HideWindow(WindowPtr(aLayer));
- end; {HideLayer}
-
- procedure ShowLayer (aLayer: LayerPtr);
- begin
- ShowWindow(WindowPtr(aLayer));
- end; {ShowLayer}
-
- procedure ShowHideLayer (aLayer: LayerPtr; showFlag: Boolean);
- begin
- ShowHide(WindowPtr(aLayer), showFlag);
- end; {ShowHideLayer}
-
- function HiddenLayer (aLayer: LayerPtr): Boolean;
- begin
- HiddenLayer := not LayerPeek(aLayer)^.visible;
- end; {HiddenLayer}
-
- function GetLayerName (aLayer: LayerPtr): Str255;
- var
- namePtr: StringPtr;
- result: Str255;
- begin
- namePtr := StringPtr(ORD(GetLayerInfo(aLayer)^.moreLayerInfo^) + $38);
- BlockMove(Ptr(namePtr), @result, SIZEOF(Str255));
- GetLayerName := result;
- end; {GetLayerName}
-
- end.